
package com.kerrykidz.scmstock.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kerrykidz.scminvoicing.dao.mapper.GblScmPrdEntityMapper;
import com.kerrykidz.scminvoicing.dao.mapper.ScmTakestkPrdEntityMapper;
import com.kerrykidz.scminvoicing.dao.model.GblScmPrdEntity;
import com.kerrykidz.scminvoicing.dao.model.ScmTakestkPrdEntity;
import com.kerrykidz.scmstock.service.IStockQueryService;
import com.rdp.framework.exception.RDPException;

/**
 * 
* @ClassName: StockQueryServiceImpl 
* @description: 库存查询模块服务类 
* @author: huanjiang 
* @date: 2014年8月21日 下午2:14:39 
* @version: V1.0
*
 */
@Service
public class StockQueryServiceImpl implements IStockQueryService {
	
	@Autowired
	private GblScmPrdEntityMapper gblScmPrdEntityMapper;
	
	@Autowired
	private ScmTakestkPrdEntityMapper scmTakestkPrdEntityMapper;
	/**
	 * 
	* @Title: findProductListForStock
	* @Description: 提供仓储管理-库存查询所需数据
	* @param: entity
	* @param: RDPException
	* @date: 2014年8月19日
	* @return: List<GblScmPrdEntity>
	* @throws RDPException
	*
	 */
	public GblScmPrdEntity findProductListForStock(GblScmPrdEntity entity)
			throws RDPException {
		entity.setIspaging(true);
		entity.setDelFlag("0");
		if(entity.getExcludeId() != null && entity.getExcludeId().size() == 0)
		{
			entity.setExcludeId(null);
		}
		List<GblScmPrdEntity> beanList = gblScmPrdEntityMapper.findProductListForStock(entity);
		if(beanList.size() > 0)
		{
			entity.setResults(beanList);
		}
		return entity;
	}
	
	/**
	 * 
	* @Title: findProductListForStock
	* @Description: 提供库存盘点-盘点时显示已盘点的商品信息
	* @param: entity
	* @param: RDPException
	* @date: 2014年8月19日
	* @return: List<GblScmPrdEntity>
	* @throws RDPException
	*
	 */
	public List<GblScmPrdEntity> findProductListForTake(GblScmPrdEntity entity,String fkTskId)
			throws RDPException {
		entity.setDelFlag("0");
		if(entity.getExcludeId() != null && entity.getExcludeId().size() == 0)
		{
			entity.setExcludeId(null);
		}
		List<GblScmPrdEntity> beanList = gblScmPrdEntityMapper.findProductListForStock(entity);
		if(beanList.size() > 0)
		{
			ScmTakestkPrdEntity scmTakestkPrd = new ScmTakestkPrdEntity();
			scmTakestkPrd.setFkTskId(fkTskId);
			//如果查询出的商品，已经盘点过，则获取盘点库存，盘点数，备注等信息，返回并显示
			for (GblScmPrdEntity gblScmPrd : beanList) {
				//设置商品id
				scmTakestkPrd.setFkPrdId(gblScmPrd.getPkPrdId());
				ScmTakestkPrdEntity beanEntity = scmTakestkPrdEntityMapper.findScmTakestkPrd(scmTakestkPrd);
				if(beanEntity != null)
				{
					gblScmPrd.setStgCnt(beanEntity.getStgCnt());
					gblScmPrd.setStkCnt(beanEntity.getStkCnt());
					gblScmPrd.setComments(beanEntity.getComments());
				}
				else {
					gblScmPrd.setComments("");
				}
			}
		}
		return beanList;
	}

}
